﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Home.Utils;
using NhanAi.DAO;
using NhanAi.DAO.Mix;
using NhanAi.Entity;
using NhanAi.App_Code;
namespace NhanAi.Admin
{
    public partial class ListPost : ListPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
           Authenticate();
            PostModel daoPost = new PostModel();
            TaxonomyDao daoTax = new TaxonomyDao();
            string searchString = Request["searchString"];
            pageNum = TypeWrapper.GetInt32(Request["page"]);
            if (pageNum == 0) pageNum = 1;
            int total = 0;
            if (Request.HttpMethod == "POST")
            {
                string ids = Request["ids"];
                if (!String.IsNullOrEmpty(ids))
                {
                    daoPost.Delete(ids);
                    SetMessage("Xóa thành công", "");
                }
            }
            List<Post> list;
            total = 0;
            if (!String.IsNullOrEmpty(searchString))
            {
                list = daoPost.ReadAdv(PAGE_SIZE, pageNum,NAConstants.LANGUAGE_VI,"post","%"+searchString+"%",5,out total);
            }
            else
            {
                list = daoPost.ReadMany(PAGE_SIZE, pageNum, NAConstants.LANGUAGE_VI,"post",null, true, -1,-1, null, null,out total);
            }
            rptData.DataSource = list;
            rptData.ItemDataBound += rptData_ItemDataBound;
            rptData.DataBind();
            paging.TotalItemCount = total;
            paging.PageNumber = pageNum;
            paging.PageSize = PAGE_SIZE;
            paging.SearchString = searchString;
            SetCurrentPage("Post");
        }

        void rptData_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            List<Taxonomy> list =( (Post)e.Item.DataItem).Taxonomies;
        //    e.Item.
           // if (sender.GetType().Name == "Repeater")
            {
              //  Repeater rpt = (Repeater)sender;
             //   rpt.Items.
             //   rpt.DataSource = list;
              //  rpt.DataBind();
            }
        }

        protected void lnkUpdateIntro_Click(object sender, EventArgs e)
        {
            PostDao dao = new PostDao();
            Application["intro"] = dao.Read("doctor", "page", NAConstants.ALL_LANGUAGE);
        }
    }
}